package com.example.inspurfabricapp.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.tomcat.util.codec.binary.StringUtils;

/**
 * 接口统一返回包装类
 *
 * @author lijiahao
 * @date 2024/06/26
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    /**
     * 状态
     */
    private int code;
    /**
     * 返回信息
     */
    private String msg;
    /**
     * 链载荷
     */
    private Object data;
    /**
     * 交易ID（事务ID）
     */
    private Object txid;


    public static Result ok(Object payload, Object txid) {
        return new Result(1, "success", StringUtils.newStringUtf8((byte[]) payload), StringUtils.newStringUtf8((byte[]) txid));
    }

    public static Result ok(Object txid) {
        return new Result(1, "success", null, StringUtils.newStringUtf8((byte[]) txid));
    }

    public static Result fail(String msg) {
        return new Result(0, msg, null, null);
    }

}
